package clientGUI.user.Controllers.ISD;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import college.Request;
import college.RequestTreatment;
import college.User;
import clientGUI.Controllers.Controller;
import clientserver.Client;
import clientserver.QueryResult;

public class ChooseSupervisorController extends Controller {

	

	private int rid;
	private ArrayList<String> candidates; // logins of candidates
	private Request  request=null;
	private ArrayList<String> rids;
	private String curs; 
	
	public ChooseSupervisorController(int id,Client cl) {

	rid=id;
	client=cl;
if(request==null)
{
	request=new Request(cl);
	request.loadFromDb(rid);
	candidates= new ArrayList<String>();
	rids= new ArrayList<String>();

}


	List <User> iseusers=User.GetUsersbyType(cl, "ISE");
	Iterator<User> iter=iseusers.iterator();
	User t;
	while(iter.hasNext())
	{
	t=iter.next();
			candidates.add(t.getLogin());
	
	}
	
	}
	
	
	public void  setid( int id)
	{


		rid=id;
		request.setId(rid);
	request.loadFromDb(rid);
	    	curs=request.getSupervisor();
		
	}

	public  ArrayList<String> getCandidates()
	{
		return candidates;
	}
	


	

	public String buildcurrentsupervisorlabel()
	{

		String curs=request.getSupervisor();

	//	if(curs==null) curs= "None";
		
		String a="Current Supervisor for request N "+rid+"is: "+curs;
		
		
		return a;		
	}
	
	public void SetSupervisor( String login)
	{
		
		request.setSupervisor(login);
		
		request.updateSupervisor();
		System.out.println("client="+client);
		System.out.println("rid="+rid);
		
	RequestTreatment.setRequestStage(client, rid, 1);
	}



// Set request section /////////////////////

public void  readonlyaddedRequests()
{
QueryResult res=RequestTreatment.getallrequestsbystage("ONLYADDED",client);

for(int i=0; i<res.rowsize();i++)
		{
	
			String s=res.getString("id");
	rids.add(s);
			res.next();
		}
	
}

public ArrayList<String>  getallrids()
{
	return rids;
}


}


